package cc.customer.saleManage.services.impl;

import cc.customer.common.service.impl.BaseService;
import cc.customer.saleManage.dao.DydisRecordMapper;
import cc.customer.saleManage.domain.DydisRecord;
import cc.customer.saleManage.services.SaleDydisRecordServices;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SaleDydisRecordServicesImp extends BaseService<DydisRecord> implements SaleDydisRecordServices {

    private static final Logger logger  = LoggerFactory.getLogger(SaleDydisRecordServicesImp.class);

    @Autowired
    private DydisRecordMapper dydisRecordMapper;

    /**外接电话查询**/
    @Override
    public List<DydisRecord> selectAllDydisRecord(DydisRecord dydisRecord) {
        try {
            List<DydisRecord> list = dydisRecordMapper.selectAllDydisRecord(dydisRecord);
            list.forEach(dydisRec ->{
                String content = dydisRec.getsDiaUrl();
                if (!StringUtils.isEmpty(content)){
                    JSONObject json = JSONObject.parseObject(content);
                    String time = json.getString("time");
                    String url = json.getString("url");
                    String urlpase = url.replaceAll("\\\\", "//");
                    dydisRec.setsDiaUrl(urlpase);
                    dydisRec.setsDiaUrlTime(time);
                }
            });
            return list;
        }catch (Exception e){
            logger.error("获取外接电话列表失败:"+e.getMessage());
        }
        return new ArrayList<>();
    }
}
